package com.burstly.lib.component.networkcomponent.burstly.html.ormma.util;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
import android.widget.VideoView;
import com.burstly.lib.component.networkcomponent.burstly.html.ormma.OrmmaController.PlayerProperties;
import com.burstly.lib.util.LoggerExt;

public class OrmmaPlayer extends VideoView
  implements MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, MediaPlayer.OnPreparedListener
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = "Ormma Player";
  private static final String TRANSIENT_TEXT = "Loading. Please Wait..";
  private String mContentURL;
  private boolean mIsReleased;
  private OrmmaPlayerListener mListener;
  private AudioManager mManager = (AudioManager)getContext().getSystemService("audio");
  private int mMutedVolume;
  private OrmmaController.PlayerProperties mPlayProperties;
  private RelativeLayout mTransientLayout;

  public OrmmaPlayer(Context paramContext)
  {
    super(paramContext);
  }

  void addTransientMessage()
  {
    if (this.mPlayProperties.isInline())
      return;
    this.mTransientLayout = new RelativeLayout(getContext());
    this.mTransientLayout.setLayoutParams(getLayoutParams());
    TextView localTextView = new TextView(getContext());
    localTextView.setText("Loading. Please Wait..");
    localTextView.setTextColor(-1);
    RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
    localLayoutParams.addRule(13);
    this.mTransientLayout.addView(localTextView, localLayoutParams);
    ((ViewGroup)getParent()).addView(this.mTransientLayout);
  }

  void clearTransientMessage()
  {
    if (this.mTransientLayout != null)
      ((ViewGroup)getParent()).removeView(this.mTransientLayout);
  }

  void displayControl()
  {
    if (this.mPlayProperties.isShowControl())
    {
      MediaController localMediaController = new MediaController(getContext());
      setMediaController(localMediaController);
      localMediaController.setAnchorView(this);
    }
  }

  void loadContent()
  {
    this.mContentURL = this.mContentURL.trim();
    this.mContentURL = OrmmaUtils.convert(this.mContentURL);
    if ((this.mContentURL == null) && (this.mListener != null))
    {
      removeView();
      this.mListener.onError();
      return;
    }
    setVideoURI(Uri.parse(this.mContentURL));
    displayControl();
    startContent();
  }

  public void onCompletion(MediaPlayer paramMediaPlayer)
  {
    if (this.mPlayProperties.isDoLoop())
      start();
    while ((!this.mPlayProperties.exitOnComplete()) && (!this.mPlayProperties.isInline()))
      return;
    releasePlayer();
  }

  public boolean onError(MediaPlayer paramMediaPlayer, int paramInt1, int paramInt2)
  {
    LoggerExt localLoggerExt = LOG;
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = Integer.valueOf(paramInt1);
    localLoggerExt.logInfo("Ormma Player", "Player error : {0}", arrayOfObject);
    clearTransientMessage();
    removeView();
    if (this.mListener != null)
      this.mListener.onError();
    return false;
  }

  public void onPrepared(MediaPlayer paramMediaPlayer)
  {
    clearTransientMessage();
    if (this.mListener != null)
      this.mListener.onPrepared();
  }

  public void playAudio()
  {
    loadContent();
  }

  public void playVideo()
  {
    if (this.mPlayProperties.isAudioMuted())
    {
      this.mMutedVolume = this.mManager.getStreamVolume(3);
      this.mManager.setStreamVolume(3, 0, 4);
    }
    loadContent();
  }

  public void releasePlayer()
  {
    if (this.mIsReleased);
    do
    {
      return;
      this.mIsReleased = true;
      stopPlayback();
      removeView();
      if ((this.mPlayProperties != null) && (this.mPlayProperties.isAudioMuted()))
        unMute();
    }
    while (this.mListener == null);
    this.mListener.onComplete();
  }

  void removeView()
  {
    ViewGroup localViewGroup = (ViewGroup)getParent();
    if (localViewGroup != null)
      localViewGroup.removeView(this);
  }

  public void setListener(OrmmaPlayerListener paramOrmmaPlayerListener)
  {
    this.mListener = paramOrmmaPlayerListener;
  }

  public void setPlayData(OrmmaController.PlayerProperties paramPlayerProperties, String paramString)
  {
    this.mIsReleased = false;
    this.mPlayProperties = paramPlayerProperties;
    this.mContentURL = paramString;
  }

  void startContent()
  {
    setOnCompletionListener(this);
    setOnErrorListener(this);
    setOnPreparedListener(this);
    if (!this.mPlayProperties.isInline())
      addTransientMessage();
    if (this.mPlayProperties.isAutoPlay())
      start();
  }

  void unMute()
  {
    this.mManager.setStreamVolume(3, this.mMutedVolume, 4);
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.ormma.util.OrmmaPlayer
 * JD-Core Version:    0.6.2
 */